var CellPager = function(list, rowNumPerPage, cellNumPerRow) {
	this.full_list = [];
	for ( var i in list) {
		this.full_list[i] = list[i];
	}
	this.rowNumPerPage = rowNumPerPage;
	this.cellNumPerRow = cellNumPerRow;
	this.filter();
};

CellPager.prototype.filter = function(prop, value) {
	this.list = [];
	var flag = (prop == null||value=='*');
	for ( var i in this.full_list) {
		if (flag || this.full_list[i][prop] == value) {
			this.list.push(this.full_list[i]);
		}
	}
	// 当前页数，初始化是第一页，第一页数字为0
	this.currPageNo = 0;
	// 开始页数是第一页，第一页数字为0
	this.startPageNo = 1;
	// 总页数
	this.totalPageNo = Math.ceil(this.list.length * 1.0
			/ (this.rowNumPerPage * this.cellNumPerRow));
	// 当前item指向，初始化为0
	this.indexOfAll = 0;
};

CellPager.prototype.getCurrentItem = function() {
	if (this.indexOfAll < this.list.length) {
		return this.list(this.indexOfAll);
	}
	return null;
};

CellPager.prototype.prevPage = function() {
	if (this.indexOfAll > 0) {
		this.indexOfAll -= 1;
		return true;
	}
	return false;
};

CellPager.prototype.gotoPage = function(index) {
	if (index <= this.list.length - 1 && index >= 0) {
		this.indexOfAll += index;
		return true;
	}
	return false;
};
CellPager.prototype.nextPage = function() {
	if (this.indexOfAll < this.list.length - 1) {
		this.indexOfAll += 1;
		return true;
	}
	return false;
};

CellPager.prototype.getNumbering = function() {
	var object = {};
	var n = ( this.currPageNo + 1 ) * this.rowNumPerPage * this.cellNumPerRow;
	object['firstIndexOfCurPage'] = this.currPageNo * this.rowNumPerPage
			* this.cellNumPerRow;
	object['lastIndexOfCurPage'] = n > this.list.length ? this.list.length : n;
	object['totalPageNo'] = this.totalPageNo;
	object['currPageNo'] = this.currPageNo;
	object['indexOfAll'] = this.indexOfAll;
	object['rowNumPerPage'] = this.rowNumPerPage;
	object['cellNumPerRow'] = this.cellNumPerRow;
	object['totalNum'] = this.list.length;
	object['test'] = 'ray';
	return object;
};

CellPager.prototype.getList = function() {
	return this.list;
};

CellPager.prototype.findUniqueByProp = function(prop, value) {
	if (this.list != null && this.list.length > 0) {
		for ( var i in list) {
			var item = list[i];
			if (item[prop] == value)
				return item;
		}
	}
	return null;
};

CellPager.prototype.findListByProp = function(prop, value) {
	var rs = [];
	if (this.list != null && this.list.length > 0) {
		for ( var i in list) {
			var item = list[i];
			if (item[prop] == value)
				rs.push(item);
		}
	}
	return rs;
};

CellPager.prototype.updateListByProp = function(name, value, prop, propVal) {
	if (this.list != null && this.list.length > 0) {
		for ( var i in list) {
			var item = list[i];
			if (item[prop] == value)
				item[prop] = propVal;
		}
	}
};
